package com.ruoyi.web;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.Company;
import com.ruoyi.system.domain.Hr;
import com.ruoyi.system.domain.Job;
import com.ruoyi.system.service.IJobService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@RestController
public class JobPostController extends BaseController {
    @Autowired
    private IJobService jobPostService;

    @RequestMapping("/jobpost")
    public AjaxResult jobpost(
            @RequestParam String title,
           // @RequestParam String jobid,
            @RequestParam String hrid,
            @RequestParam String poststat,
            @RequestParam String recruitstat,
            @RequestParam String jobkind,
            @RequestParam String updatetime,
            @RequestParam String salary,
            @RequestParam String loc,
            @RequestParam String educ,
            @RequestParam String jobdesc,
            @RequestParam String exprdesc) {
        System.out.println("发布新工作，现在在映射函数中");
        Job jobPost = new Job();
        jobPost.setJobName(title);
        //jobid部分
//        try {
//            Long jobIdLong = Long.parseLong(jobid);
//            jobPost.setJobId(jobIdLong);
//        } catch (NumberFormatException e) {
//            return AjaxResult.error("Invalid job ID format.");
//        }

        // 将 hrid 从 String 转换为 Long
        try {
            Long hrIdLong = Long.parseLong(hrid);
            jobPost.setHrId(hrIdLong);
        } catch (NumberFormatException e) {
            return AjaxResult.error("Invalid HR ID format.");
        }

        //jobPost.setHrId(hrid);

        //jobPost.setJobId(jobid);
        //jobPost.setHrId(hrid);
        jobPost.setJobPoststat(poststat);
        jobPost.setJobRecruitstat(recruitstat);

        jobPost.setJobKind(jobkind);
        try {
            jobPost.setJobInfoupdatetime(updatetime);
        } catch (NumberFormatException e) {
            return AjaxResult.error("Invalid updatetime format.");
        }

        jobPost.setJobSalrange(salary);
        jobPost.setJobWorkaddr(loc);
        jobPost.setJobEdureq(educ);
        jobPost.setJobDesc(jobdesc);
        jobPost.setJobWorkexp(exprdesc);

        return toAjax(jobPostService.insertJob(jobPost));
    }

//    @RequestMapping("/jobdetail")
//    public AjaxResult jobdetail(HttpServletRequest request, HttpServletResponse response){
//        String token = request.getParameter("token");
//        Long hrid = myTokenService.getloginid(token);
//        Job job = JobService.selectHrByHrId(hrid);
//
//        //Company company = companyService.selectCompanyByCompanyId(hr.getCompanyId());
//        Map<String,Object> data = new HashMap<>();
//        data.put("hr",hr);
//        data.put("company",company);
//        return new AjaxResult(200,"返回成功",data);
//
//    }
//
//    @RequestMapping("/updatejobdetail")
//    public AjaxResult updatejobdetail(@RequestParam String hrid, @RequestParam String hrname, @RequestParam String hrTel, @RequestParam String hrpwd,@RequestParam String hrpos){
////        Hr hr = hrService.selectHrByHrId(Long.valueOf(hrid));
////        hr.setHrName(hrname);
////        hr.setHrPos(hrpos);
////        hr.setHrPwd(hrpwd);
////        return toAjax(hrService.updateHr(hr));
//    }









}